/**
 * 
 */
package com.jonosoft.photocast.viewer.web.client.ui;

import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlexTable;
import com.jonosoft.photocast.viewer.web.client.LibraryImageMap;
import com.jonosoft.photocast.viewer.web.client.photocast.Photocast;
import com.jonosoft.photocast.viewer.web.client.photocast.PhotocastController;
import com.jonosoft.photocast.viewer.web.client.photocast.PhotocastRecieveHandler;

/**
 * TODO Add description PhotocastViewer (com.jonosoft.photocast.viewer.web.client.PhotocastViewer)
 *
 * @author jon
 *
 */
public class PhotocastViewer extends Composite {
	
	private final FlexTable layoutTable = new FlexTable();
	private final AppToolbar appToolbar = new AppToolbar();
	private final PhotocastFileList photocastFileList = new PhotocastFileList();
	private final ImageBrowser imageBrowser = new ImageBrowser();
	private final PhotocastReciever photocastReciever = new PhotocastReciever();
	
    public PhotocastViewer() {
    	initWidget(layoutTable);
    	
    	layoutTable.setWidth("100%");

		layoutTable.insertRow(0);
		layoutTable.insertRow(0);
		layoutTable.addCell(0);
		layoutTable.addCell(1);
		layoutTable.addCell(1);
		layoutTable.getFlexCellFormatter().setColSpan(0, 0, 2);

		layoutTable.setWidget(0, 0, appToolbar);
		layoutTable.setWidget(1, 0, photocastFileList);
		layoutTable.setWidget(1, 1, imageBrowser);
    	
    	PhotocastController.loadPhotocast("http://web.mac.com/skater0i/iPhoto/landon-pics-for-web/index.rss", photocastReciever);
    }

	private class PhotocastReciever implements PhotocastRecieveHandler {
		/**
		 * @see com.jonosoft.photocast.viewer.web.client.photocast.PhotocastRecieveHandler#onCompletion(com.jonosoft.photocast.viewer.web.client.photocast.Photocast)
		 */
		public void onCompletion(Photocast photocast) {
			/*Debug.Out(photocast.getTitle());
			Debug.Out(photocast.getDescription());
			DOM.setStyleAttribute(Debug.Out(photocast.getJSONRepresentation().toString()), "color", "#ccc");*/
			
			/*ArrayList pics = photocast.getPhotocastItems();
			ArrayList imageURLs = new ArrayList();
			Iterator i = pics.iterator();
			
			while (i.hasNext())
				imageURLs.add(((PhotocastItem) i.next()).getLink() + "?transform=small");*/
			
			imageBrowser.setImages(LibraryImageMap.createFromPhotocast(photocast));
		}
	}
	
}
